<include file="public@header"/>
</head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('ask/index',['listid'=>$listid,'status'=>$status])}">问卷题目</a></li>
        <li class="active"><a href="{:url('ask/add',['listid'=>$listid])}">添加</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('ask/addPost')}">
        <div class="form-group">
            <label for="input-name" class="col-sm-2 control-label">题干<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" id="input-name" name="title">
            </div>
        </div>
        <div class="form-group">
            <label for="input-name" class="col-sm-2 control-label">选项个数(正整数)<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" id="input-count" name="count_option" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
            </div>
        </div>	
        <div class="form-group">
            <label for="input-name" class="col-sm-2 control-label">最多可选(正整数)<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" id="input-name" name="count_max" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
            </div>
        </div>		
        <div class="form-group">
            <label for="input-name" class="col-sm-2 control-label">最少可选(正整数)<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" id="input-name" name="count_min" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}">
            </div>
        </div>	
        <div class="form-group">
            <label for="input-name" class="col-sm-2 control-label">选项<span class="form-required">*</span></label>
            <div class="col-md-6 col-sm-10" id="options">

            </div>
        </div>	



        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
				<input type="hidden" class="form-control" name="listid" value="{$listid}">
                <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
                <a class="btn btn-default" href="{:url('ask/index',array('listid'=>$listid,'status'=>$status))}">{:lang('BACK')}</a>
            </div>
        </div>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>


<script type="text/javascript">

    $(function () {

        $("#input-count").on("change",function(){
            html='';
            var count = $(this).val();
            for(i=0;i<count;i++){
                var thumbId = '#thumbnail' + i;
                html+='<input type="text" class="form-control" id="input-name" name="option[]" style="margin-bottom:3px">';
                html+= '<input type="hidden" name="thumb' + i + '"' + ' id=thumbnail' + i;
                html+= ' value="">';
                html+= '<a href="javascript:uploadOneImage(' + "'" + '图片上传' + "'," + "'" + thumbId + "'" + ');">';
                html+= '<img src="__TMPL__/public/assets/images/default-thumbnail.png"';
                html+= 'id="thumbnail' + i + '-preview"';
                html+= 'style="cursor: pointer;max-width:100px;max-height:100px;"/>';
                html+= '</a>';
                html+= '<input type="button" onclick="cancelThumb(' + i +')" class="btn btn-sm btn-cancel-thumbnail' + i + '" value="取消图片">';
            }
            $("#options").html(html);
        });

    });


    function cancelThumb(i) {
        $("#thumbnail" + i + "-preview").attr('src','__TMPL__/public/assets/images/default-thumbnail.png');
        $("#thumbnail" + i).val('');
    }







</script>
</body>
</html>